package ar.uade.edu.fain.ad.client.web.servlet.caja.calculoComisiones;

import ar.uade.edu.fain.ad.client.web.servlet.caja.CajaServlet;
import ar.uade.edu.fain.ad.common.exception.PedidoPendienteException;
import ar.uade.edu.fain.ad.common.transfer.LocalVO;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class CalculoComisionesServlet
 */
public class CalculoComisionesServlet extends CajaServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see CajaServlet#CajaServlet()
	 */
	public CalculoComisionesServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		final LocalVO localVO = new LocalVO();
		localVO.setId(Long.valueOf(
				request.getSession().getAttribute("localId").toString()));
		try {
			getCajaDelegate().calcularComisiones(localVO , new Date());
			forward(getViewBasePath() +
					"calculoComisiones/comisionesCalculadas.jsp", 
					request, response);
		} catch (PedidoPendienteException e) {
			request.setAttribute("pedidos", e.getPendientes());
			forward(getViewBasePath() +
					"calculoComisiones/pedidosPendientes.jsp", 
					request, response);
		}
	}

}
